﻿#pragma once

#include <QtWidgets/QMainWindow>
#include <QTimer>
#include <QFileDialog>
#include <QEvent> 
#include <QMouseEvent>
#include <QRubberBand>
#include <QSettings>
#include <QButtonGroup>
#include <QGraphicsItem>
#include <QGraphicsRectItem>
#include <QBoxLayOut>

#include "ui_CarPos.h"
#include "Camera.h"
#include "Capture.h"
#include "Plc.h"
#include "CalibrateCamera.h"
#include "Car.h"
#include "Ground.h"


class CarPos : public QMainWindow
{
	Q_OBJECT

public:
	CarPos(QWidget* parent = nullptr);
	~CarPos();

private:
	bool eventFilter(QObject* obj, QEvent* event);
	void move_car(QVariant start, QVariant end);
	void draw();

	Ui::CarPosClass ui;
	Capture* _capture;
	CalibrateCamera* _cc;

	//显示抓拍
	QGraphicsScene* scene, * scene_2;
	QPoint _origin, _origin_last;
	bool in_drawing = false;
	QRubberBand* rubberBand;

	//显示动画
	QGraphicsScene* _scene_car;
	QGraphicsPixmapItem* car_direction = nullptr;

	cv::Mat _img_src;
	cv::Mat _img_crop;
	cv::Rect _rect;

	Car* _car = nullptr;
	Ground* _ground = nullptr;

	//section3: plc
	Plc* _plc;

	//线程 plc
	QThread* _th_plc;

	//timer: 抓拍
	QTimer tmr_capture;

	//pos
	bool to_east, to_west; //向东 向西
	float pos_prev; //前一位置

	QSettings* _settings;

	Camera* camera_1;

	bool is_to_east = false;

private slots:
	void showpic(cv::Mat mat, QGraphicsScene* scene);
	void plc_rw(QString value);
	QPoint pos_global(QEvent* event);
	QPoint pos_scene(QPoint pt);

	void save_pos();

	void action_tmr_capture();

};
